package 特别的数191;

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner=new Scanner(System.in);
		int n=scanner.nextInt();
		int sum=0;
		for(int i=1;i<=n;i++) {
			int num=i;
			while(num>0) {
				int s=num%10;
				if(s==1||s==2||s==0||s==9) {
					sum+=i;
					break;
				}
				num/=10;
			}
		}
		System.out.println(sum);
	}
}
